//
//  UIImage+frameworkImg.m
//  AFNetworking
//
//  Created by 尹亚坤 on 2018/10/31.
//

#import "UIImage+frameworkImg.h"

@implementation UIImage (frameworkImg)
+ (UIImage *)yk_imageWithName:(NSString *)imgName targetClass:(Class)cls{
    NSBundle *currentBundle = [NSBundle bundleForClass:cls];//[self wg_subBundleWithBundleName:@"YKFuncation" targetClass:cls];//[NSBundle bundleForClass:[self class]];
                                                                                                            // 获取当前bundle的名称
    NSString *currentBundleName = currentBundle.infoDictionary[@"CFBundleName"];
        // 获取图片的路径
    NSInteger scale = (NSInteger)UIScreen.mainScreen.scale;

    NSString *phontoName;
    if (scale == 0) {
       phontoName = [NSString stringWithFormat:@"%@.png",imgName];
    }else{
        phontoName = [NSString stringWithFormat:@"%@@%ldx.png",imgName,scale];
    }
    NSString *imagePath = [currentBundle pathForResource:phontoName ofType:nil inDirectory:[NSString stringWithFormat:@"%@.bundle",currentBundleName]];
        //
    UIImage *img = [UIImage imageWithContentsOfFile:imagePath];
    return img;
}
+ (NSBundle *)wg_subBundleWithBundleName:(NSString *)bundleName targetClass:(Class)targetClass{
        //并没有拿到子bundle
    NSBundle *bundle = [NSBundle bundleForClass:targetClass];
        //在这个路径下找到子bundle的路径
    NSString *path = [bundle pathForResource:bundleName ofType:@"bundle"];
        //根据路径拿到子bundle
    return path?[NSBundle bundleWithPath:path]:[NSBundle mainBundle];
}
@end
